package com.mzy.linear_struct.代码随想录.动态规划;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: mizy3
 * @Date: 2024/09/01/下午5:13
 * @Description:
 */
public class 背包问题01 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int bagweight = scanner.nextInt();

        int[] weight = new int[n];
        int[] value = new int[n];

        for (int i = 0; i < n; ++i) {
            weight[i] = scanner.nextInt();
        }
        for (int j = 0; j < n; ++j) {
            value[j] = scanner.nextInt();
        }

        // dp[i][j] i代表i种物品，背包大小为j最多装多少价值的东西
        int[][] dp = new int[n][bagweight + 1];

        for (int i = 0; i < dp[0].length; i++) {
            dp[0][i] = 0;
        }

        for (int j = weight[0]; j <= bagweight; j++) {
            dp[0][j] = value[0];
        }

        for (int i = 1; i < dp.length; i++) {
            for (int j = 1; j < dp[i].length; j++) {
                if (j > weight[i]) {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
           System.out.println(Arrays.toString(dp[i]));
        }
        System.out.println(dp[n - 1][bagweight]);
    }
}
